/**
 * // Definition for a Node.
 * function Node(val, next, random) {
 *    this.val = val;
 *    this.next = next;
 *    this.random = random;
 * };
 */

/**
 * @param {Node} head
 * @return {Node}
 */
var copyRandomList = function (head) {
    const map = new WeakMap()
    const copyLinkList = function (node) {
        if (map.has(node)) return map.get(node)
        let tmp_node = new Node()
        map.set(node, tmp_node)
        tmp_node.val = node.val
        tmp_node.next = copyLinkList(node.next)
        tmp_node.random = copyLinkList(node.random)
        return tmp_node
    }
    return copyLinkList(head)
};